package com.manualtrader.frame;

import javax.swing.JDesktopPane;
import com.jbooktrader.platform.model.Dispatcher;
import com.jbooktrader.platform.model.JBookTraderException;
import com.jbooktrader.platform.model.Mode;
import com.jbooktrader.platform.optimizer.StrategyParams;
import com.jbooktrader.platform.trader.Trader;
import com.jbooktrader.platform.trader.TraderAssistant;
import com.jbooktrader.strategy.AG1209M5;
import com.jbooktrader.strategy.AG1212M5;
import com.jbooktrader.strategy.AU1212Trader;
import com.jbooktrader.strategy.XAGUSDH4Trader;
import com.jbooktrader.strategy.XAUUSDM5Trader;
import com.manualtrader.trader.ManualTrader;

public class MainDesktop extends JDesktopPane {

	private static final long serialVersionUID = 1L;

	private MarketTable marketTable = new MarketTable();
	private TraderToolBox2 traderToolBox;
	private TraderInfoArea traderInfoArea;
	private Trader trader;
	private TraderAssistant traderAssistant;
	private ManualTrader manualTrader;
	
	public MainDesktop(Dispatcher dispatcher) {
		trader = dispatcher.getTrader();
		traderAssistant = trader.getAssistant();
		
		manualTrader = new ManualTrader();
		try {
			manualTrader.getAssistant().connect();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		StrategyParams optimizationParams = new StrategyParams();
		
		XAGUSDH4Trader strategy1 = null;
		AG1209M5 strategy2 = null;
		AG1212M5 strategy3 = null;
		XAUUSDM5Trader strategy4 = null;
		AU1212Trader strategy5 = null;
		try {
			dispatcher.setMode(Mode.Query);
			strategy1 = new XAGUSDH4Trader(optimizationParams);
			strategy2 = new AG1209M5(optimizationParams);
			strategy3 = new AG1212M5(optimizationParams);
			strategy4 = new XAUUSDM5Trader(optimizationParams);
			strategy5 = new AU1212Trader(optimizationParams);
			traderAssistant.addStrategy(strategy1);
			traderAssistant.addStrategy(strategy2);
			traderAssistant.addStrategy(strategy3);
			traderAssistant.addStrategy(strategy4);
			traderAssistant.addStrategy(strategy5);
		} catch (JBookTraderException e) {
			e.printStackTrace();
		}
		
		traderToolBox = new TraderToolBox2(trader,manualTrader);
		traderInfoArea = new TraderInfoArea(manualTrader,trader);
		traderToolBox.setLocation(20,150);
		marketTable.startRefresh();
		marketTable.setLocation(20, 20);
		marketTable.startRefresh(trader);
		this.add(marketTable);
		this.add(traderToolBox);
		this.add(traderInfoArea);
	}


	
}
